const mongoose = require('mongoose');
/**
 * user type
 * @typedef {object} user
 * @property {string} email - 邮箱
 * @property {string} password - 密码
 * @property {string} name - 姓名
 * @property {string} phone - 手机号
 * @property {string} remark - 备注
 * @property {string} createBy - 创建人
 * @property {string} updateBy - 更新人
 * @property {boolean} active - 状态
 * @property {string} avatar - 头像
 * @property {string} role - 角色
 * @property {string} createAt - 创建时间
 * @property {string} updateAt - 更新时间
 */
const UserSchema = new mongoose.Schema({
  email: {
    type: String,
    required: true,
    unique: true,
  },
  phone: {
    type: String,
    default: ''
  },
  password: { type: String, required: true },
  name: { type: String, default: 'user' },
  role: { type: mongoose.Schema.Types.ObjectId, ref: 'Role', },

  createdAt: { type: Date, default: Date.now },
  updatedAt: { type: Date, default: Date.now },
  avatar: { type: String, default: '' },
  active: {
    type: Boolean,
    default: true
  },
  remark: { type: String, default: '' },
  createBy: { type: String, default: '' },
  updateBy: { type: String, default: '' },

});

const User = mongoose.model('User', UserSchema);

module.exports = User;